package com.android.webttest.Adapter;

import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.widget.VideoView;

import androidx.databinding.BindingAdapter;

public class VideoBindingAdapters {

    @BindingAdapter("videoPath")
    public static void setVideoPath(VideoView videoView, String url) {
        if (url != null && !url.isEmpty()) {
            try {
                videoView.setVideoURI(Uri.parse(url));
                videoView.start(); // 可选自动播放
            } catch (Exception e) {
                Log.e("VideoBinding", "Error setting video path: " + url, e);
                videoView.setVisibility(View.INVISIBLE); // 失败时仍保留空间
            }
        } else {
            videoView.setVisibility(View.INVISIBLE); // 保留空间但不显示
            videoView.stopPlayback(); // 停止播放
        }
    }
}
